package cn.pugle.guava;

import com.google.common.util.concurrent.RateLimiter;

/**
 * @author tzp
 * @since 2020/11/19
 */
@SuppressWarnings("UnstableApiUsage")
public class RateLimiterTest {
    public static void main(String[] args) throws InterruptedException {
        RateLimiter rateLimiter = RateLimiter.create(5);
//        System.out.println(rateLimiter.tryAcquire());
//        System.out.println(rateLimiter.tryAcquire());
//        Thread.sleep(200);
//        System.out.println(rateLimiter.tryAcquire());
//        System.out.println(rateLimiter.tryAcquire());
//        Thread.sleep(200);
//        System.out.println(rateLimiter.tryAcquire());
//        System.out.println(rateLimiter.tryAcquire());
//        System.out.println(rateLimiter.tryAcquire());
        Thread.sleep(2000);
        System.out.println(rateLimiter.tryAcquire(1));
        System.out.println(rateLimiter.tryAcquire(100000));
    }
}
